@extends('admin.admin')

@section('content')
        <!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        商铺管理
        <small>商铺列表</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="/admin"><i class="fa fa-dashboard"></i> 控制面板</a></li>
        <li ><a href="/admin/shop">商铺管理</a></li>
        <li class="active">商铺列表</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="row">
        <div class="col-xs-12">
            <div class="box box-primary ">
                <div class="box-body table-responsive">
                    <a href="{{route('admin.shop.create')}}" class="btn btn-success"><i class="icon glyphicon glyphicon-plus"></i>添加</a>

                    {!! Form::model(@$shop,array('route' => 'admin.shop.index','method' => 'get','class'=>'form-search form-inline pull-right')) !!}
                    <div class="form-group">
                        {!! Form::text('shop_name',$search['shop_name'],['class'=>'form-control','placeholder'=>'商铺名称'])!!}
                    </div>
                    <button type="submit" class="btn btn-primary">搜索</button>
                    <button type="button" onclick="window.location.href='/admin/shop'" class="btn btn-default">重置</button>
                    {!! Form::close() !!}
                </div>
            </div><!-- end .box box-primary -->

            <div class="box box-primary">
                <div class="box-header">
                    <h3 class="box-title">商铺列表</h3>
                    <div class="pull-right">
                        <a href="{{route('admin.shop.create')}}" type="button" class="btn btn-block btn-success btn-xs"><i class="icon  glyphicon glyphicon-plus"></i> 添加</a>
                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover">
                        <tr>
                            <th style="width:50px;">ID</th>
                            <th style="width: 200px;">商铺名称</th>
                            <th>商铺描述</th>
                            <th style="width: 80px;text-align: center;">是否展示</th>
                            <th style="width: 150px;">操作</th>

                        </tr>
                        @foreach ($shop as $item)
                        <tr>
                            <td>{{$item->id}}</td>
                            <td>{{$item->shop_name}}</td>                            
                            <td>{{$item->shop_desc}}</td>
                            <!-- <td>{{$item->sort_order}}</td> -->
                       
                            <td style="text-align: center" class="is_show" id="{{$item->id}}" is_show="{{$item->is_show}}">@if($item->is_show==1)
                                    <i  class="glyphicon glyphicon-ok" title="展示" style=" cursor: pointer;color: green;"></i>
                                @else
                                    <i  class="glyphicon glyphicon-remove " title="不展示" style=" cursor: pointer;color: red;"></i>
                                @endif
                            </td>
                            
                            <td>
                                <a href="{{Route('admin.shop.edit',$item->id)}}" type="button" class="btn  btn-default btn-xs"><i class="icon  glyphicon glyphicon-edit"></i> 修改</a>
                                <button type="button" class="btn  btn-danger btn-xs"  data-toggle="modal" data-target="#modal{{$item->id}}"><i class="icon  glyphicon glyphicon-remove"></i> 删除</button>

                                <div id="modal{{$item->id}}" class="modal fade">
                                    <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                <h4 class="modal-title">删除警告:</h4>
                                            </div>
                                            <div class="modal-body">
                                                <p>确认要删除商铺[{{$item->shop_name}}]吗?</p>
                                            </div>
                                            <div class="modal-footer">

                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                                <button type="button" class="btn btn-danger01" itemid="{{$item->id}}">删除</button>

                                            </div>
                                        </div><!-- /.modal-content -->
                                    </div><!-- /.modal-dialog -->
                                </div><!-- /.modal -->

                            </td>
                        </tr>
                        @endforeach
         
                    </table>

                    {!! Form::hidden('_method', 'POST') !!}

                </div>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
            {!! $shop->render() !!}
        </div>
    </div>

</section>
<!-- /.content -->

<script >
    $('.is_show').on('click',function(){
        var el = $(this);
        var id = el.attr('id');
       
        var url = "{{Route('admin.shop.toggleShow')}}";
        $.ajax({
            url:url+"/?id="+id,
            type:'get',
            dataType:'json',
            success:function(result){
                if(result.info){
                    if(result.is_show==1){
                        el.find('.glyphicon').removeClass('glyphicon-remove');
                        el.find('.glyphicon').addClass('glyphicon-ok');
                        el.find('.glyphicon').css("color","green");

                    }else{
                        el.find('.glyphicon').removeClass('glyphicon-ok');
                        el.find('.glyphicon').addClass('glyphicon-remove');
                        el.find('.glyphicon').css("color","red");

                    }

                }
            }
        });
    });

</script>

<script>

        $('.btn-danger01').on('click',function(e){
            e.preventDefault();
            var id = $(this).attr("itemid");
            if(!id) return false;

            $.ajax({
                url:'/admin/shop/'+id+"?"+Math.random(),
                type:'delete',
                data:{id:id,'_token':'{{csrf_token()}}'},
                dataType:"json",
                success:function(result){

                    if(result.status){
                      window.location.reload();

                    }else{
                    alert(result.message);
                        window.location.reload();
                    }

                }

            });

        });


    </script>


<script>
    $('.btn-danger').on('click',function(){
        console.log('11');
    });
</script>
@endsection